package com.gidgabs.modules.api.controller;

import java.util.List;
import java.util.Map;

import com.gidgabs.modules.api.service.TbProductPropertyService;
import com.gidgabs.modules.entity.TbProductPropertyEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gidgabs.common.utils.PageUtils;
import com.gidgabs.common.utils.Query;
import com.gidgabs.common.utils.R;

/**
 * 产品属性表
 *
 * @author lanyonglin
 * @email www.baidu.com
 * @date 2018-07-02 10:07:40
 */
@RestController
@RequestMapping("/api/productproperty")
public class TbProductPropertyController {
    @Autowired
    private TbProductPropertyService productPropertyService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("productproperty:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<TbProductPropertyEntity> productPropertyList = productPropertyService.queryList(query);
        int total = productPropertyService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(productPropertyList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("productproperty:info")
    public R info(@PathVariable("id") Integer id) {
        TbProductPropertyEntity productProperty = productPropertyService.queryObject(id);

        return R.ok().put("productProperty", productProperty);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("productproperty:save")
    public R save(@RequestBody TbProductPropertyEntity productProperty) {
        productPropertyService.save(productProperty);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("productproperty:update")
    public R update(@RequestBody TbProductPropertyEntity productProperty) {
        productPropertyService.update(productProperty);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("productproperty:delete")
    public R delete(@RequestBody Integer[] ids) {
        productPropertyService.deleteBatch(ids);

        return R.ok();
    }

}
